from pydantic import BaseModel, Field
from typing import List, Optional

class AliasAuthor(BaseModel):
    id:Optional[str]=None

class LoginModel(BaseModel):
    code: str
    userInfo: dict
class SubmitAliasRequest(BaseModel):
    waiguanId:str
    userId:str
    alias:str

class ToggleLikeRequest(BaseModel):
    waiguanId:Optional[str] = None
    userId:Optional[str] = None
    createTime:Optional[str] = None
    deleted:Optional[bool] = None
    updateTime:Optional[str] = None
    id:Optional[str] = Field(default=None, alias="_id")

class EvaluateModel(BaseModel):
    evaluateUserId: Optional[str] =None
    tuanId: Optional[str] =None
    leader: dict
    members: List[dict]

class Address(BaseModel):
    contact: Optional[str] =None
    contactType: Optional[str]=None
    createTime: Optional[str]=None
    deleted: Optional[bool]=None
    faction: Optional[str]=None
    name: Optional[str]=None
    server: Optional[str]=None
    signature: Optional[str]=None
    updateTime: Optional[str]=None
    user_id: Optional[str]=None
    id: Optional[str]= Field(alias='_id')  # 使用 Field 别名将 _id 映射到 id

    class Config:
        populate_by_name = True  # 允许通过字段名和别名同时访问
        allow_population_by_field_name = True  # 允许使用字段名填充

class Gift(BaseModel):
    address:Address | None
    avatar:Optional[str] =None
    image:Optional[str] =None
    name: Optional[str] =None
    price: Optional[str] =None
    selected:bool =False
    userId:Optional[str] =None
    userName:Optional[str] =None

class TuanCreateModel(BaseModel):
    createTime: Optional[str] =None
    creater_id:Optional[str] =None
    deleted: bool = False
    duration: Optional[str] =None
    gifts: List[Gift]
    name: Optional[str] =None
    server:Optional[str] =None
    # 团状态 0:拼团中 1:已完成 2:已评价
    status:int =0
    updateTime: Optional[str] =None
    id: Optional[str]= Field(alias='_id')  # 使用 Field 别名将 _id 映射到 id

    class Config:
        populate_by_name = True  # 允许通过字段名和别名同时访问
        allow_population_by_field_name = True  # 允许使用字段名填充


# 用户模型定义
class UserModel(BaseModel):
    openid: Optional[str] =None
    # 用户昵称
    nickname: Optional[str] =None
    gender: int =0
    session_key: Optional[str] =None
    # 用户头像URL
    avatar_url: Optional[str] =None
    ##是否删除
    deleted: bool = False
    createTime: Optional[str] =None
    updateTime: Optional[str] =None


class AddressSaveModel(BaseModel):
    id:Optional[str] =None
    user_id: Optional[str] =None
    name: Optional[str] =None
    faction: Optional[str] =None
    server: Optional[str] =None
    contactType: Optional[str] =None
    contact: Optional[str] =None
    signature: Optional[str] =None
    createTime: Optional[str] =None
    updateTime: Optional[str] =None
    deleted: bool = False